use std::thread;
use std::thread::sleep;
use std::time::Duration;
use rand::{Rng};
use concurrency::Metrics;

fn main() {
    let mut metrics = Metrics::new();

    for _ in 0..10 {
        work(metrics.clone());
    }


    loop {
        sleep(Duration::from_secs(1));
        let metrics_cl = metrics.clone();
        let res = metrics_cl.snapshot();

        println!("res is {:?}", res);
    }
}


fn work(metrics: Metrics) {
    thread::spawn(move || {
        loop {
            let mut rng = rand::thread_rng();

            thread::sleep(Duration::from_millis(rng.gen_range(50..800)));
            let page = rng.gen_range(1..5);
            metrics.inc(format!("req.page.{}", page).as_str());
        }
    });
}
